package handler

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"sort"
	"src/zeus/logger"
	"strings"
)

func CreateSign(signParams map[string]interface{}, appSecret string) string {
	var (
		params = make([]string, 0)
	)
	for key := range signParams {
		if key == "sign" {
			continue
		}
		value := fmt.Sprintf("%s=%v", key, signParams[key])
		params = append(params, value)
	}
	sort.Strings(params)
	signStr := fmt.Sprintf("%s%s", strings.Join(params, ""), appSecret)
	data := []byte(signStr)
	hash := md5.Sum(data)
	hashString := hex.EncodeToString(hash[:])
	logger.Debug(logger.LogKey_LoginFlow, "签名参数: ", signStr, "  ==> ", hashString)
	return hashString
}
